package com.atguigu.algorithm;

import java.util.Stack;

public class ReverseStack {
    public void reverse(Stack<Integer> stack){
        if(stack.isEmpty()){
            return;
        }
        int i=reverseStack(stack);
        reverse(stack);
        stack.push(i);
    }
    //这个操作是将栈的最底部元素取出
    public int reverseStack(Stack<Integer> stack){
        int result=stack.pop();
        if(stack.isEmpty()){
            return result;
        }else{
            int last=reverseStack(stack);
            stack.push(result);
            return last;
        }
    }
}
